<template>
  <div>
    <city-header></city-header>
    <city-search :cities="cities"></city-search>
    <city-list :cities="cities" :hot="hotCities" :letter="letter"></city-list>
    <city-alphabet :cities="cities" @change="getAlohabet"></city-alphabet>
  </div>
</template>

<script>
import CityHeader from "@/pages/city/components/header";
import CitySearch from "@/pages/city/components/search";
import CityList from "@/pages/city/components/list";
import CityAlphabet from "@/pages/city/components/alphabet";
import axios from "axios";

export default {
  name: "City",
  components: {
    CityHeader,
    CitySearch,
    CityList,
    CityAlphabet
  },
  data() {
    return {
      cities: {},
      hotCities: [],
      letter: ""
    };
  },
  methods: {
    getCityInfo() {
      axios.get("/api/city.json").then(this.getCityInfoSucc);
    },
    getCityInfoSucc(res) {
      res = res.data;
      if (res.ret && res.data) {
        const data = res.data;
        this.cities = data.cities;
        this.hotCities = data.hotCities;
      }
    },
    getAlohabet(letter) {
      // console.log(letter)
      this.letter = letter;
    }
  },
  mounted() {
    this.getCityInfo(); //页面加载完成后执行
  }
};
</script>

<style lang="stylus" scoped></style>
